package com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.R;
import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.model.Article;

import java.util.List;

public class ArticleAdapter extends RecyclerView.Adapter<ArticleAdapter.ViewHolder> {

    private Context context;
    private List<Article> articleList;


    public ArticleAdapter(Context context,  List<Article> articleList) {
        this.context = context;
        this.articleList = articleList;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView avatarImage;
        TextView articleTitle;
        TextView articleDescription;
        TextView articleTag;


        public ViewHolder(View view) {
            super(view);
            articleTitle = view.findViewById(R.id.articleTitle);
            articleDescription = view.findViewById(R.id.articleDescription);
            articleTag = view.findViewById(R.id.articleTag);
        }
    }

    @Override
    public ArticleAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_article, parent, false);
        return new ArticleAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ArticleAdapter.ViewHolder holder, int position) {
        Article article = articleList.get(position);
//        byte[] imageBytes = article.getAvatarBytes();
        /*if (imageBytes != null) {
            Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
            holder.avatarImage.setImageBitmap(bitmap);
        }*/
        holder.articleTitle.setText(article.getTitle());
        holder.articleDescription.setText(article.getDescription());
        holder.articleTag.setText(article.getTag());
    }

    @Override
    public int getItemCount() {
        return articleList.size();
    }
    
}
